/*
 * Copyright (C) 2019 The Android Open Source Project
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package com.x.component.connectivity;

import android.annotation.Nullable;
import android.app.ActivityManager;
import android.app.ActivityTaskManager;
import android.app.AlarmManager;
import android.app.IActivityManager;
import android.app.IActivityTaskManager;
import android.app.INotificationManager;
import android.app.IWallpaperManager;
import android.app.KeyguardManager;
import android.app.NotificationManager;
import android.app.StatsManager;
import android.app.UiModeManager;
import android.app.WallpaperManager;
import android.app.admin.DevicePolicyManager;
import android.app.role.RoleManager;
import android.app.smartspace.SmartspaceManager;
import android.app.trust.TrustManager;
import android.app.usage.StorageStatsManager;
import android.content.ClipboardManager;
import android.content.ContentResolver;
import android.content.Context;
import android.content.SharedPreferences;
import android.content.om.OverlayManager;
import android.content.pm.IPackageManager;
import android.content.pm.LauncherApps;
import android.content.pm.PackageManager;
import android.content.pm.ShortcutManager;
import android.content.res.Resources;
import android.hardware.SensorManager;
import android.hardware.SensorPrivacyManager;
import android.hardware.devicestate.DeviceStateManager;
import android.hardware.display.AmbientDisplayConfiguration;
import android.hardware.display.ColorDisplayManager;
import android.hardware.display.DisplayManager;
import android.hardware.face.FaceManager;
import android.hardware.fingerprint.FingerprintManager;
import android.hardware.input.InputManager;
import android.location.LocationManager;
import android.media.AudioManager;
import android.media.IAudioService;
import android.media.MediaRouter2Manager;
import android.media.projection.MediaProjectionManager;
import android.media.session.MediaSessionManager;
import android.net.ConnectivityManager;
import android.net.NetworkScoreManager;
import android.net.wifi.WifiManager;
import android.os.BatteryStats;
import android.os.HardwarePropertiesManager;
import android.os.PowerExemptionManager;
import android.os.PowerManager;
import android.os.ServiceManager;
import android.os.UserManager;
import android.os.Vibrator;
import android.os.storage.StorageManager;
import android.permission.PermissionManager;
import android.safetycenter.SafetyCenterManager;
import android.service.dreams.DreamService;
import android.service.dreams.IDreamManager;
import android.telecom.TelecomManager;
import android.telephony.CarrierConfigManager;
import android.telephony.SubscriptionManager;
import android.telephony.TelephonyManager;
import android.view.Choreographer;
import android.view.CrossWindowBlurListeners;
import android.view.IWindowManager;
import android.view.LayoutInflater;
import android.view.ViewConfiguration;
import android.view.WindowManager;
import android.view.WindowManagerGlobal;
import android.view.accessibility.AccessibilityManager;
import android.view.accessibility.CaptioningManager;
import android.view.inputmethod.InputMethodManager;

import com.android.internal.app.IBatteryStats;
import com.android.internal.appwidget.IAppWidgetService;
import com.android.internal.jank.InteractionJankMonitor;
import com.android.internal.statusbar.IStatusBarService;
import com.android.internal.util.LatencyTracker;
import java.util.Optional;

/**
 * Provides Non-SystemUI, Framework-Owned instances to the dependency graph.
 */
public class FrameworkServicesModule {

	static AccessibilityManager provideAccessibilityManager(Context context) {
		return context.getSystemService(AccessibilityManager.class);
	}

	static ActivityManager provideActivityManager(Context context) {
		return context.getSystemService(ActivityManager.class);
	}

	static AlarmManager provideAlarmManager(Context context) {
		return context.getSystemService(AlarmManager.class);
	}

	/** */

	public AmbientDisplayConfiguration provideAmbientDisplayConfiguration(Context context) {
		return new AmbientDisplayConfiguration(context);
	}

	public static AudioManager provideAudioManager(Context context) {
		return context.getSystemService(AudioManager.class);
	}

	static CaptioningManager provideCaptioningManager(Context context) {
		return context.getSystemService(CaptioningManager.class);
	}

	/** */

	public Choreographer providesChoreographer() {
		return Choreographer.getInstance();
	}

	static ColorDisplayManager provideColorDisplayManager(Context context) {
		return context.getSystemService(ColorDisplayManager.class);
	}

	static ConnectivityManager provideConnectivityManagager(Context context) {
		return context.getSystemService(ConnectivityManager.class);
	}

	static ContentResolver provideContentResolver(Context context) {
		return context.getContentResolver();
	}

	static DevicePolicyManager provideDevicePolicyManager(Context context) {
		return context.getSystemService(DevicePolicyManager.class);
	}

	static CrossWindowBlurListeners provideCrossWindowBlurListeners() {
		return CrossWindowBlurListeners.getInstance();
	}

	public static int provideDisplayId(Context context) {
		return context.getDisplayId();
	}

	public static DisplayManager provideDisplayManager(Context context) {
		return context.getSystemService(DisplayManager.class);
	}

	public static HardwarePropertiesManager provideHardwarePropertiesManager(Context context) {
		return context.getSystemService(HardwarePropertiesManager.class);
	}

	public static InputManager provideInputManager(Context context) {
		return context.getSystemService(InputManager.class);
	}

	public static DeviceStateManager provideDeviceStateManager(Context context) {
		return context.getSystemService(DeviceStateManager.class);
	}

	public static IActivityManager provideIActivityManager() {
		return ActivityManager.getService();
	}

	public static ActivityTaskManager provideActivityTaskManager() {
		return ActivityTaskManager.getInstance();
	}

	public static IActivityTaskManager provideIActivityTaskManager() {
		return ActivityTaskManager.getService();
	}

	public static IAudioService provideIAudioService() {
		return IAudioService.Stub.asInterface(ServiceManager.getService(Context.AUDIO_SERVICE));
	}

	public static IBatteryStats provideIBatteryStats() {
		return IBatteryStats.Stub.asInterface(ServiceManager.getService(BatteryStats.SERVICE_NAME));
	}

	public static IDreamManager provideIDreamManager() {
		return IDreamManager.Stub.asInterface(ServiceManager.checkService(DreamService.DREAM_SERVICE));
	}

	@Nullable
	public static FaceManager provideFaceManager(Context context) {
		return context.getSystemService(FaceManager.class);

	}

	@Nullable
	public static FingerprintManager providesFingerprintManager(Context context) {
		return context.getSystemService(FingerprintManager.class);
	}

	public static InteractionJankMonitor provideInteractionJankMonitor() {
		return InteractionJankMonitor.getInstance();
	}

	public static InputMethodManager provideInputMethodManager(Context context) {
		return context.getSystemService(InputMethodManager.class);
	}

	public static IAppWidgetService provideIAppWidgetService() {
		return IAppWidgetService.Stub.asInterface(ServiceManager.getService(Context.APPWIDGET_SERVICE));
	}

	public static IPackageManager provideIPackageManager() {
		return IPackageManager.Stub.asInterface(ServiceManager.getService("package"));
	}

	public static IStatusBarService provideIStatusBarService() {
		return IStatusBarService.Stub.asInterface(ServiceManager.getService(Context.STATUS_BAR_SERVICE));
	}

	@Nullable
	public static IWallpaperManager provideIWallPaperManager() {
		return IWallpaperManager.Stub.asInterface(ServiceManager.getService(Context.WALLPAPER_SERVICE));
	}

	public static IWindowManager provideIWindowManager() {
		return WindowManagerGlobal.getWindowManagerService();
	}

	public static KeyguardManager provideKeyguardManager(Context context) {
		return context.getSystemService(KeyguardManager.class);
	}

	public static LatencyTracker provideLatencyTracker(Context context) {
		return LatencyTracker.getInstance(context);
	}

	public static LauncherApps provideLauncherApps(Context context) {
		return context.getSystemService(LauncherApps.class);
	}

	/** */

	public LayoutInflater providerLayoutInflater(Context context) {
		return LayoutInflater.from(context);
	}

	public static MediaProjectionManager provideMediaProjectionManager(Context context) {
		return context.getSystemService(MediaProjectionManager.class);
	}

	public static MediaRouter2Manager provideMediaRouter2Manager(Context context) {
		return MediaRouter2Manager.getInstance(context);
	}

	public static MediaSessionManager provideMediaSessionManager(Context context) {
		return context.getSystemService(MediaSessionManager.class);
	}

	public static NetworkScoreManager provideNetworkScoreManager(Context context) {
		return context.getSystemService(NetworkScoreManager.class);
	}

	public static NotificationManager provideNotificationManager(Context context) {
		return context.getSystemService(NotificationManager.class);
	}

	/** */

	public INotificationManager provideINotificationManager() {
		return INotificationManager.Stub.asInterface(ServiceManager.getService(Context.NOTIFICATION_SERVICE));
	}

	public static PackageManager providePackageManager(Context context) {
		return context.getPackageManager();
	}

	public static PackageManagerWrapper providePackageManagerWrapper() {
		return PackageManagerWrapper.getInstance();
	}

	/** */

	public static PowerManager providePowerManager(Context context) {
		return context.getSystemService(PowerManager.class);
	}

	public static LocationManager provideLocationManager(Context context) {
		return context.getSystemService(LocationManager.class);
	}

	public static StorageManager provideStorageManager(Context context) {
		return context.getSystemService(StorageManager.class);
	}
	
	public static StorageStatsManager provideStorageStatsManager(Context context) {
		return context.getSystemService(StorageStatsManager.class);
	}

	/** */

	public static PowerExemptionManager providePowerExemptionManager(Context context) {
		return context.getSystemService(PowerExemptionManager.class);
	}

	public static UiModeManager provideUiModeManager(Context context) {
		return context.getSystemService(UiModeManager.class);
	}

	public static Resources provideResources(Context context) {
		return context.getResources();
	}

	public static RoleManager provideRoleManager(Context context) {
		return context.getSystemService(RoleManager.class);
	}

	public static SensorManager providesSensorManager(Context context) {
		return context.getSystemService(SensorManager.class);
	}

	public static SensorPrivacyManager provideSensorPrivacyManager(Context context) {
		return context.getSystemService(SensorPrivacyManager.class);
	}

	public static ShortcutManager provideShortcutManager(Context context) {
		return context.getSystemService(ShortcutManager.class);
	}

	public static StatsManager provideStatsManager(Context context) {
		return context.getSystemService(StatsManager.class);
	}

	public static SubscriptionManager provideSubcriptionManager(Context context) {
		return context.getSystemService(SubscriptionManager.class);
	}

	@Nullable
	public static TelecomManager provideTelecomManager(Context context) {
		return context.getSystemService(TelecomManager.class);
	}

	public static Optional<TelecomManager> provideOptionalTelecomManager(Context context) {
		return Optional.ofNullable(context.getSystemService(TelecomManager.class));
	}

	public static TelephonyManager provideTelephonyManager(Context context) {
		return context.getSystemService(TelephonyManager.class);
	}

	public static boolean provideIsTestHarness() {
		return ActivityManager.isRunningInUserTestHarness();
	}

	public static TrustManager provideTrustManager(Context context) {
		return context.getSystemService(TrustManager.class);
	}

	@Nullable
	public static Vibrator provideVibrator(Context context) {
		return context.getSystemService(Vibrator.class);
	}

	static Optional<Vibrator> provideOptionalVibrator(Context context) {
		return Optional.ofNullable(context.getSystemService(Vibrator.class));
	}

	static ViewConfiguration provideViewConfiguration(Context context) {
		return ViewConfiguration.get(context);
	}

	public static UserManager provideUserManager(Context context) {
		return context.getSystemService(UserManager.class);
	}

	static WallpaperManager provideWallpaperManager(Context context) {
		return context.getSystemService(WallpaperManager.class);
	}

	@Nullable
	static WifiManager provideWifiManager(Context context) {
		return context.getSystemService(WifiManager.class);
	}

	static OverlayManager provideOverlayManager(Context context) {
		return context.getSystemService(OverlayManager.class);
	}

	static CarrierConfigManager provideCarrierConfigManager(Context context) {
		return context.getSystemService(CarrierConfigManager.class);
	}

	static WindowManager provideWindowManager(Context context) {
		return context.getSystemService(WindowManager.class);
	}

	static PermissionManager providePermissionManager(Context context) {
		PermissionManager pm = context.getSystemService(PermissionManager.class);
		if (pm != null) {
			pm.initializeUsageHelper();
		}
		return pm;
	}

	static ClipboardManager provideClipboardManager(Context context) {
		return context.getSystemService(ClipboardManager.class);
	}

	static SmartspaceManager provideSmartspaceManager(Context context) {
		return context.getSystemService(SmartspaceManager.class);
	}

	static SafetyCenterManager provideSafetyCenterManager(Context context) {
		return context.getSystemService(SafetyCenterManager.class);
	}
}
